#include "associationbutton.h"

AssociationButton::AssociationButton(QGraphicsObject *parent) : RelationButton(parent)
{
    this->_lineGraphicsItem.setPen(this->_pen);
    this->_lineGraphicsItem.setLine(QLine(10, 2, 10, 18));

    this->addToGroup(&this->_lineGraphicsItem);
}


AssociationButton::~AssociationButton()
{
    qDebug() << "deleting association relation button";
}

DraggedRelation* AssociationButton::draggedRelation()
{
    DraggedRelation *draggedRelation = new DraggedRelation();
    draggedRelation->setStartItem(this->_relationalItem);

    UmlRelation *relation = new UmlRelation(UmlRelation::UmlAssociationRelationType);

    draggedRelation->setRelation(relation);

    return draggedRelation;
}

QVariant AssociationButton::itemChange(GraphicsItemChange change, const QVariant &value)
{
    QVariant result = RelationButton::itemChange(change, value);

    if (change == QGraphicsItem::ItemSceneHasChanged) {
        this->_lineGraphicsItem.setParentItem(this);
        this->addToGroup(&this->_lineGraphicsItem);
    }

    return result;
}
